package com.pzhu.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class GetSessionServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        //设置请求和响应编码格式
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        //获取Session对象
        HttpSession hs=req.getSession();
        //获取Session对象数据
        System.out.println("GetSessionServlet.service()"+hs.getId());
        System.out.println("GetSessionServlet.service()"+hs.getAttribute("name"));
        //浏览器访问提示语
        resp.getWriter().write("这是GetSessionServlet");
    }
}
